package com.hanhanxiaochong.zhongxiangchuanmei.view.my.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.CollectItemBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.util.glide.GlideImgManager;
import com.hanhanxiaochong.zhongxiangchuanmei.widget.StarBar;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by RockPhoenix on 2018/6/6.
 */

public class CollectAdapter extends CommonAdapter<CollectItemBean> {

    private String  type;

    public CollectAdapter(Context context, int layoutId, List<CollectItemBean> datas,String type) {
        super(context, layoutId, datas);
        this.type = type;
    }

    @Override
    protected void convert(ViewHolder holder, CollectItemBean bean, int position) {
        //判断是项目还是店铺
        if (type.equals("1")) {
            ImageView ivGoodPic = holder.getView(R.id.iv_good_pic);
            ImageView selfSupport = holder.getView(R.id.iv_self_support);
            TextView goodName = holder.getView(R.id.tv_good_name);
            TextView vipPrice = holder.getView(R.id.tv_vip_price);
            TextView normalPrice = holder.getView(R.id.tv_normal_price);
            ImageView becomVip = holder.getView(R.id.iv_becom_vip);
            GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + (bean.getPic().split(",")[0]), R.mipmap.img_error, R.mipmap.img_error, ivGoodPic);
            selfSupport.setVisibility(bean.getSelf_support().equals("y") ? View.VISIBLE : View.GONE);
            goodName.setText(bean.getName());
            vipPrice.setText(String.format(ResourcesUtils.getString(R.string.vip_good_price), bean.getPrice_vip()));
            normalPrice.setText(String.format(ResourcesUtils.getString(R.string.normal_good_price), bean.getPrice()));
            holder.itemView.setOnClickListener(v -> mOnItemClickListener.onItemClick(this, position));
        } else {
            TextView shopName = holder.getView(R.id.tv_shop_name);
            StarBar shopStar = holder.getView(R.id.shop_star);
            TextView shopScore = holder.getView(R.id.tv_shop_score);
            TextView shopEvaluation = holder.getView(R.id.tv_shop_evaluation);
            TextView shopDistance = holder.getView(R.id.tv_shop_distance);
            TextView shopAddress = holder.getView(R.id.tv_shop_address);
            ImageView shopLogo = holder.getView(R.id.iv_shop_logo);
            shopName.setText(bean.getName());
            shopStar.setStarMark(Float.parseFloat(bean.getScore()));
            shopScore.setText(String.format(ResourcesUtils.getString(R.string.good_score), bean.getScore()));
            shopEvaluation.setText(String.format(ResourcesUtils.getString(R.string.good_evaluation), bean.getSt_num()));
            shopDistance.setText(String.format(ResourcesUtils.getString(R.string.shop_distance),
                    new DecimalFormat("0.00").format(Double.parseDouble(bean.getMQ_DISTANCE()))));
            shopAddress.setText(bean.getProvince() + bean.getCity() + bean.getArea() + bean.getAddresser());
            GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + bean.getPic().split(",")[0], R.mipmap.img_error, R.mipmap.img_error, shopLogo, 0);
            holder.setOnClickListener(R.id.item_nearby_shop, v -> mOnItemClickListener.onItemClick(this, position));
        }
    }
}
